package com.xuelangyun.form.form.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xuelangyun.form.form.entity.DyFormTemplateEntity;

/**
 * 动态表单模板
 *
 * @author weiqing.hk
 * @date 2024年5月12日11:36:36
 */
@Mapper
public interface IFormTemplateDao extends BaseMapper<DyFormTemplateEntity> {

    @Select(" <script>"
            + "select n1.* "
            + " from ng_form_template n1 ,  "
            + " (select t1.code , max(t1.version) as version from ng_form_template t1 group by t1.code ) n2  "
            + " where n1.code = n2.code and n1.version = n2.version"
            + " <if test=\"entity.name!=null and entity.name!=''\">"
            + "  and n1.name like concat(concat('%', #{entity.name}),'%') "
            + " </if >"
            + " order by n1.create_time desc "
            + "</script>")
    public IPage<DyFormTemplateEntity> page(Page<DyFormTemplateEntity> page, @Param("entity") DyFormTemplateEntity entity);


    @Select("select max(substr(code,2)) from ng_form_template")
    public String getMaxCode();

}
